package com.dxf.sysadmin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dxf.common.utils.ResultJson;
import com.dxf.sysadmin.entity.Clazz;
import com.dxf.sysadmin.entity.EvaluteType;
import com.dxf.sysadmin.entity.qo.MyPage;
import com.dxf.sysadmin.mapper.EvaluteTypeMapper;
import com.dxf.sysadmin.service.EvaluteTypeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 评价类型 服务实现类
 */
@Service
public class EvaluteTypeServiceImpl extends ServiceImpl<EvaluteTypeMapper, EvaluteType> implements EvaluteTypeService {

    /**
     *评价类型列表分页查询
     */
    @Override
    public ResultJson typePage(MyPage qry) {
        Page<EvaluteType> page = new Page<>(qry.getPage(), qry.getLimit());

        IPage<EvaluteType> iPage = page(page,
                new QueryWrapper<EvaluteType>().lambda().orderByAsc(EvaluteType::getSortCode));
        Map<String, Object> map = new HashMap<>();
        map.put("rows",iPage.getRecords());
        map.put("total",iPage.getTotal());
        return ResultJson.ok().data(map);
    }

    /**
     *更具id列表删除评价类型
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ResultJson deleteType(List<Long> list) {
        removeByIds(list);
        return ResultJson.ok();
    }

    /**
     *新增或者更新评价类型
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ResultJson saveOrUpdateType(EvaluteType type) {
        saveOrUpdate(type);
        return ResultJson.ok();
    }
}
